package main

func maxArea(height []int) int {
	min := func(a int, b int) int {
		if a < b {
			return a
		} else {
			return b
		}
	}

	n := len(height)
	if n == 2 {
		return min(height[0], height[1])
	}

	l, r := 0, n-1
	maxVol := 0
	for l < r {
		vol := min(height[l], height[r]) * (r - l)
		if vol > maxVol {
			maxVol = vol
		}
		if height[l] < height[r] {
			l++
		} else {
			r--
		}
	}

	return maxVol
}
